
package com.tools.cleanmaster.model.cloud;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * 后台扫描后会触发云端请求，对扫描出来的未知路径进行识别，是否为垃圾路径 该类用于管理所有需要去服务端检查的未知路径
 */
public class TrashUnknowPathData {
    private static TrashUnknowPathData mInstance = null;
    private final int mBunchNum = 20;
    private LinkedList<NormalPath> mNomalPath = new LinkedList<NormalPath>();
    private LinkedList<NormalPath> mSpecialPaths = new LinkedList<NormalPath>();

    private TrashUnknowPathData() {
    }

    public static TrashUnknowPathData getInstance() {
        if (mInstance == null) {
            synchronized (TrashUnknowPathData.class) {
                if (mInstance == null) {
                    mInstance = new TrashUnknowPathData();
                }
            }
        }
        return mInstance;
    }

    public class NormalPath {
        public String mLevelOne;
        public String mLevelTwo;
        public String mLevelThree;
    }

    public void addNomalUnknowPath(String one, String two, String three) {
        NormalPath normalPath = new NormalPath();
        normalPath.mLevelOne = one != null ? one.toLowerCase() : one;
        normalPath.mLevelTwo = two != null ? two.toLowerCase() : two;
        normalPath.mLevelThree = three != null ? three.toLowerCase() : three;
        mNomalPath.add(normalPath);
    }

    public void addSpecialUnknowPath(String one, String two) {
        NormalPath normalPath = new NormalPath();
        normalPath.mLevelOne = one != null ? one.toLowerCase() : one;
        normalPath.mLevelTwo = two != null ? two.toLowerCase() : two;
        mSpecialPaths.add(normalPath);
    }

    public List<NormalPath> getNomalPaths() {
        List<NormalPath> paths = new ArrayList<NormalPath>();
        if (mNomalPath.size() > mBunchNum) {
            for (int i = 0; i < mBunchNum; i++) {
                NormalPath path = mNomalPath.pollFirst();
                if (path != null) {
                    paths.add(path);
                }
            }
        } else {
            paths = new ArrayList<NormalPath>(mNomalPath);
            mNomalPath.clear();
        }
        return paths;
    }

    public List<NormalPath> getSpecialPaths() {
        List<NormalPath> paths = new ArrayList<NormalPath>();
        if (mSpecialPaths.size() > mBunchNum) {
            for (int i = 0; i < mBunchNum; i++) {
                NormalPath path = mSpecialPaths.pollFirst();
                if (path != null) {
                    paths.add(path);
                }
            }
        } else {
            paths = new ArrayList<NormalPath>(mSpecialPaths);
            mSpecialPaths.clear();
        }
        return paths;
    }
}
